package com.intel.two.service.medical.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.intel.two.common.LayuiPageVo;

import com.intel.two.mapper.medical.HealthMapper;

import com.intel.two.pojo.medical.Health;
import com.intel.two.service.medical.HealthService;
import com.intel.two.vo.medical.HealthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author:xiaofeia
 * @DATE:2022/10/15
 */
@Service
public class HealthServiceImpl implements HealthService {
    @Autowired
    private HealthMapper healthMapper;
    @Override
    public LayuiPageVo<Health> healthPageData(Map<String, Object> params) {

        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");

        PageHelper.startPage(page,limit);
        List<Health> healths =  healthMapper.healthPageData(params);


        PageInfo<Health> healthPageInfo = new PageInfo<>(healths);
        // 把mybatis 的分页数据结构中的 数据 封装到 layui的 分页数据结构中
        LayuiPageVo<Health> layuiPageVo = new LayuiPageVo<>();
        layuiPageVo.setCode(0);
        layuiPageVo.setMsg("健康信息分页列表数据");
        layuiPageVo.setCount(healthPageInfo.getTotal());  // 总记录数
        layuiPageVo.setData(healthPageInfo.getList());  // 分页列表数据
        return layuiPageVo;
    }

    @Override
    public int addHealth(Health health) {
        return healthMapper.addHealth(health);

    }

    @Override
    public int deleteHealthById(Integer health_id) {
        return healthMapper.deleteHealthById(health_id);
    }

    @Override
    public int deletHealthIds(String health_ids) {
        String[] _ids = health_ids.split(",");
        List<Integer> list = new ArrayList<>();
        for(int i=0;i < _ids.length; i++){
            list.add(Integer.parseInt(_ids[i]));
        }
        System.out.println(list);
        return healthMapper.deletHealthIds(list);

    }

    @Override
    public int updateHealth(Health health) {
        return healthMapper.updateHealth(health);
    }

    @Override
    public List<HealthVo> sexBarData() {
        return healthMapper.sexBarData();
    }
}
